import Router from 'koa-router';
import {mapKeysToCamelCase, sequelize} from "../../../config/mysqlDB.js";
import {QueryTypes} from "sequelize";
import userModel from "../../../models/system/userModel.js";

const router = new Router({
  prefix: '/seq'
});


router.post('/query', async (ctx, next) => {
  let sql = 'select * from user';
  let result = await sequelize.query(sql, {
    type: QueryTypes.SELECT,
    mapToModel: true,
    model: userModel,
    // mapToModel: true
  });
/*  //将查询结果转换为DTO,就是将查询结果model绑定;
  let mapResult = result.map(item => {
    return userModel.build(item).dataValues;
  });
  mapResult = mapKeysToCamelCase(mapResult);*/
  ctx.body = result;
})

export default router;